package com.scholarship.modules.backend.service;

import com.scholarship.common.entity.RetCode;
import com.scholarship.common.entity.RetResponse;
import com.scholarship.common.entity.RetResult;
import com.scholarship.modules.backend.entity.RewardTypeDetail;
import com.scholarship.modules.backend.mapper.RewardTypeDetailMapper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author zhz
 * @date 2021/5/10 17:27
 * 备注：针对奖学金具体加分项表的增删改查
 */
@Service
public class RewardTypeDetailService {

    @Autowired
    RewardTypeDetailMapper rewardTypeDetailMapper;

    /**
     * 功能：列出所有信息
     * @return 链表：奖学金具体加分项（id,type_id,name,score,detail,is_upload_file,table_name）
     */
    public List<RewardTypeDetail> listRewardTypeDetail(){
        return rewardTypeDetailMapper.listRewardTypeDetail();
    }


    /**
     * 功能：增加某个信息，如果某个信息不存在则返回错误
     * @param rewardTypeDetail 奖学金具体加分项
     * @return -1 : 必填字段没有填写
     *          else : 成功添加奖学金具体加分项信息
     */
    public Integer addRewardTypeDetail(RewardTypeDetail rewardTypeDetail){
        if(rewardTypeDetail.getTypeId()==null||rewardTypeDetail.getName()==null||rewardTypeDetail.getScore()==null||rewardTypeDetail.getIsUploadFile()==null){
            return -1;
        }
        return rewardTypeDetailMapper.addRewardTypeDetail(rewardTypeDetail);
    }


    /**
     * 功能：修改某个信息，如果某个信息不存在则返回错误，成功了则显示修改的id
     * @param rewardTypeDetail 奖学金具体加分项
     * @return -1 : id不存在
     *          else : sucess
     */
    public Integer updateRewardTypeDetail(RewardTypeDetail rewardTypeDetail){
        RewardTypeDetail before = rewardTypeDetailMapper.getRewardTypeDetail(rewardTypeDetail.getId());
        if(before==null){
            return -1;
        }
//        System.out.println("原数据："+before.toString());
        Integer line = rewardTypeDetailMapper.updateRewardTypeDetail(rewardTypeDetail);
//        System.out.println("修改为："+rewardTypeDetailMapper.getRewardTypeDetail(rewardTypeDetail.getId()));
        return line;
    }


    /**
     * 功能：删除某个信息，如果某个信息不存在则返回错误，成功了则显示修改的id
     * @param rewardTypeDetail 奖学金具体加分项
     * @return -1 : id不存在
     *          else : sucess
     */
    public Integer deleteRewardTypeDetail(RewardTypeDetail rewardTypeDetail){
        RewardTypeDetail before = rewardTypeDetailMapper.getRewardTypeDetail(rewardTypeDetail.getId());
        if(before==null){
            return -1;
        }
//        System.out.println("原数据："+before.toString());
        Integer line = rewardTypeDetailMapper.deleteRewardTypeDetail(rewardTypeDetail.getId());
        return line;
    }
}
